<html>
<head>
    <link rel="stylesheet" href="/layui/css/layui.css">
    <meta charset="utf-8" />
    <link rel="stylesheet" href="/kingeditor/themes/default/default.css" />
    <link rel="stylesheet" href="/kingeditor/plugins/code/prettify.css" />
    <script charset="utf-8" src="/kingeditor/kindeditor-all.js"></script>
    <script charset="utf-8" src="/kingeditor/lang/zh-CN.js"></script>
    <script charset="utf-8" src="/kingeditor/plugins/code/prettify.js"></script>
    <style>
        .img-item{
            margin: 10px;
            position: relative;
            z-index: 1;
        }
        .close
        {
            position: absolute;
            top: -10px;
            right: -10px;
            z-index: 999;
            background-color: #fff;
        }
    </style>
</head>
<body>

<form class="layui-form" action="" style="margin-top: 20px;margin-right: 30px;">

    <input type="hidden" name="goods_id" value="{$data.goods_id}">
    <div class="layui-form-item">
        <label class="layui-form-label">名称</label>
        <div class="layui-input-block">
            <input type="text" name="name" id="name" required  lay-verify="required" autocomplete="off" class="layui-input" value="{$data.name}">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">商品分类</label>
        <div class="layui-input-block">
            {volist name="category" id="vo"}
            <input type="checkbox" name="category_id[]" title="{$vo.name}" value="{$vo.id}"
                   {in name="$vo.id" value="$data.category_id"}
                   checked
                   {/in}
            >
            {/volist}
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">封面图</label>
        <div class="layui-input-block" >

            <button type="button" class="layui-btn" id="test1">
                <i class="layui-icon">&#xe67c;</i>选择图片
            </button>
            <div id="img" style="margin-top: 20px;">
                {if condition="$data.cover != ''"}
                <img src='{$data.cover}' style='width: 120px;'>
                <input type='hidden' name='cover' value='{$data.cover}'/>
                {/if}

            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">轮播图</label>
        <div class="layui-input-block" >
            <button type="button" class="layui-btn" id="test2">
                <i class="layui-icon">&#xe67c;</i>选择图片
            </button>
        </div>
        <div id="img2" style="display: flex;margin-left: 100px; flex-wrap: wrap">
            {volist name='data.images' id="vo"}
            <div class='img-item'>
                <img src='{$vo}' style='width: 120px;'>
                <img src='/image/close.png' style='width: 20px;' class='close' onclick='delete1(this)'>
                <input type='hidden' name='images[]' value='{$vo}'/>
            </div>
            {/volist}
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">分享大图(450*800)</label>
        <div class="layui-input-block" >

            <button type="button" class="layui-btn" id="test3">
                <i class="layui-icon">&#xe67c;</i>选择图片
            </button>
            <div id="img3" style="margin-top: 20px;">
                {if condition="$data.share != ''"}
                <img src='{$data.share}' style='width: 120px;'>
                <input type='hidden' name='share' value='{$data.share}'/>
                {/if}

            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">首页模块</label>
        <div class="layui-input-block">
            {volist name="index" id="vo"}
            <input type="checkbox" name="index_id[]" title="{$vo.name}" value="{$vo.id}"
                   {in name="$vo.id" value="$data.index_id"}
                   checked
                   {/in}
            >
            {/volist}
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">虎牙</label>
        <div class="layui-input-block">
            <input type="text" name="tiger_tee" id="tiger_tee" required  lay-verify="required" autocomplete="off" class="layui-input" value="{$data.tiger_tee}">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">价格</label>
        <div class="layui-input-block">
            <input type="text" name="price" id="price" required  lay-verify="required" autocomplete="off" class="layui-input" value="{$data.price}">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">原价</label>
        <div class="layui-input-block">
            <input type="text" name="old_price" id="old_price" required  lay-verify="required" autocomplete="off" class="layui-input" value="{$data.old_price}">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">是否限制仅维修点可买</label>
        <div class="layui-input-block">
            <input type="radio" name="is_limit" value="1" title="是" {if condition="$data.is_limit == 1"}checked{/if}>
            <input type="radio" name="is_limit" value="0" title="否" {if condition="$data.is_limit == 0"}checked{/if}>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">兑换地址</label>
        <div class="layui-input-block">
            <input type="text" name="address" id="address" required  lay-verify="required" autocomplete="off" class="layui-input" value="{$data.address}">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">库存</label>
        <div class="layui-input-block">
            <input type="text" name="num" id="num" required  lay-verify="required" autocomplete="off" class="layui-input" value="{$data.num}">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">详情</label>
        <div class="layui-input-block">
            <textarea name="details" id="details" style="width:700px;height:200px;visibility:hidden;"><?php echo htmlspecialchars($data['details']); ?></textarea>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">赞助商</label>
        <div class="layui-input-block">
            <input type="text" name="sponsor" id="sponsor" required  lay-verify="required" autocomplete="off" class="layui-input" value="{$data.sponsor}">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">赞助商ID</label>
        <div class="layui-input-block">
            <input type="text" name="company_id" id="company_id" required  lay-verify="required" autocomplete="off" class="layui-input" value="{$data.company_id}">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">经度</label>
        <div class="layui-input-block">
            <input type="text" name="lat" id="lat" required  lay-verify="required" autocomplete="off" class="layui-input" value="{$data.lat}">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">纬度</label>
        <div class="layui-input-block">
            <input type="text" name="lng" id="lng" required  lay-verify="required" autocomplete="off" class="layui-input" value="{$data.lng}">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">运费</label>
        <div class="layui-input-block">
            <input type="text" name="fee" id="fee" required  lay-verify="required" autocomplete="off" class="layui-input" value="{$data.fee}">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">优惠券</label>
        <div class="layui-input-block">
            <input type="text" name="coupon_id" id="coupon_id" required  lay-verify="required" autocomplete="off" class="layui-input" value="{$data.coupon_id}">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">企业ID</label>
        <div class="layui-input-block">
            <input type="text" name="uid" id="uid" required  lay-verify="required" autocomplete="off" class="layui-input" value="{$data.uid}">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">企业营业时间</label>
        <div class="layui-input-block">
            <input type="text" name="business_hours" id="business_hours" required  lay-verify="required" autocomplete="off" class="layui-input" value="{$data.business_hours}">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">企业电话</label>
        <div class="layui-input-block">
            <input type="text" name="business_tel" id="business_tel" required  lay-verify="required" autocomplete="off" class="layui-input" value="{$data.business_tel}">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">喜欢人数</label>
        <div class="layui-input-block">
            <input type="text" name="like" id="like" required  lay-verify="required" autocomplete="off" class="layui-input" value="{$data.like}">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">合伙人佣金</label>
        <div class="layui-input-block">
            <input type="text" name="add_money" id="add_money" required  lay-verify="required" autocomplete="off" class="layui-input" value="{$data.add_money}">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">合伙人虎牙</label>
        <div class="layui-input-block">
            <input type="text" name="add_tiger" id="add_tiger" required  lay-verify="required" autocomplete="off" class="layui-input" value="{$data.add_tiger}">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">是否限购</label>
        <div class="layui-input-block">
            <input type="radio" name="is_limit_buy" value="1" title="是" {if condition="$data.is_limit_buy == 1"}checked{/if}>
            <input type="radio" name="is_limit_buy" value="0" title="否"  {if condition="$data.is_limit_buy == 0"}checked{/if}>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">限购周期</label>
        <div class="layui-input-block">
            <input type="text" name="limit_buy_time" id="limit_buy_time" required  lay-verify="required" autocomplete="off" class="layui-input" value="{$data.limit_buy_time}">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">限购次数</label>
        <div class="layui-input-block">
            <input type="text" name="limit_buy_num" id="limit_buy_num" required  lay-verify="required" autocomplete="off" class="layui-input" value="{$data.limit_buy_num?:1}">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">是否限时</label>
        <div class="layui-input-block">
            <input type="radio" name="is_time" value="1" title="是" {if condition="$data.is_time == 1"}checked{/if}>
            <input type="radio" name="is_time" value="0" title="否"  {if condition="$data.is_time == 0"}checked{/if}>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">结束时间</label>
        <div class="layui-input-block">
            <input type="datetime-local" name="end_time" id="end_time" required  lay-verify="required" autocomplete="off" class="layui-input" value="{$data.end_time}">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">排序(从大到小)</label>
        <div class="layui-input-block">
            <input type="number" name="sort" id="sort" required  lay-verify="required" autocomplete="off" class="layui-input" value="{$data.sort}">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">标题</label>
        <div class="layui-input-block">
            <input type="text" name="wx_title" id="wx_title" required  lay-verify="required" autocomplete="off" class="layui-input" value="{$data.wx_title}">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">内容</label>
        <div class="layui-input-block">
            <input type="text" name="wx_content" id="wx_content" required  lay-verify="required" autocomplete="off" class="layui-input" value="{$data.wx_content}">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">电话</label>
        <div class="layui-input-block">
            <input type="text" name="wx_tel" id="wx_tel" required  lay-verify="required" autocomplete="off" class="layui-input" value="{$data.wx_tel}">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">回复数字</label>
        <div class="layui-input-block">
            <input type="text" name="wx_num" id="wx_num" required  lay-verify="required" autocomplete="off" class="layui-input" value="{$data.wx_num}">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">评论奖励优惠券ID</label>
        <div class="layui-input-block">
            <input type="text" name="ticket_prize" id="ticket_prize" required  lay-verify="required" autocomplete="off" class="layui-input" value="{$data.ticket_prize}">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">评论奖励虎牙</label>
        <div class="layui-input-block">
            <input type="text" name="tiger_tee_prize" id="tiger_tee_prize" required  lay-verify="required" autocomplete="off" class="layui-input" value="{$data.tiger_tee_prize}">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">是否推荐</label>
        <div class="layui-input-block">
            <input type="radio" name="is_recommend" value="1" title="是" {if condition="$data.is_recommend == 1"}checked{/if}>
            <input type="radio" name="is_recommend" value="0" title="否"  {if condition="$data.is_recommend == 0"}checked{/if}>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="formDemo">提交</button>
        </div>
    </div>
</form>


<script src="/js/jquery-1.10.1.min.js" type="text/javascript"></script>
<script src="/layui/layui.js"></script>
<script>
    var editor1;
    KindEditor.ready(function(K) {
        editor1 = K.create('textarea[name="details"]', {
            cssPath : '/kingeditor/plugins/code/prettify.css',
            uploadJson : '/ops/goods/upload',
            afterCreate : function() {
                var self = this;
                K.ctrl(document, 13, function() {
                    self.sync();
                    K('form[name=example]')[0].submit();
                });
                K.ctrl(self.edit.doc, 13, function() {
                    self.sync();
                    K('form[name=example]')[0].submit();
                });
            },
            afterBlur: function(){this.sync();}
        });
        prettyPrint();
    });
    //Demo
    layui.use('form', function(){
        var form = layui.form;
        form.render();

        //监听提交
        form.on('submit(formDemo)', function(data){
            var data = data.field;
            data.details = editor1.html()

            $.post("/ops/goods/edit", data, function (res) {
                var res = JSON.parse(res);
                if(res.errno==0){
                    layer.msg('操作成功')
                }

                window.parent.location.reload();
            });
            return false;
        });
    });
    layui.use('upload', function(){
        var upload = layui.upload;

        //执行实例
        var uploadInst = upload.render({
            elem: '#test2' //绑定元素
            ,url: '/ops/company/upload', //上传接口
            field: 'image'
            ,done: function(res){
                // var data = JSON.parse(res)
                var data = res;
                if(data.errno == 0){
                    var str = "<div class='img-item'><img src='"+data.data.url+"' style='width: 120px;'><img src='/image/close.png' style='width: 20px;' class='close' onclick='delete1(this)'>"
                    str += "<input type='hidden' name='images[]' value='"+data.data.url+"'/></div>"

                    $('#img2').append(str);
                }else {
                    alert(data.errmsg);
                }

            }
            ,error: function(){
                //请求异常回调
            }
        });
    });


    layui.use('upload', function(){
        var upload = layui.upload;

        //执行实例
        var uploadInst = upload.render({
            elem: '#test1' //绑定元素
            ,url: '/ops/company/upload', //上传接口
            field: 'image'
            ,done: function(res){
                // var data = JSON.parse(res)
                var data = res;
                if(data.errno == 0){
                    var str = "<div id=\"test1\"><img src='"+data.data.url+"' style='width: 120px;'>"
                    str += "<input type='hidden' name='cover' value='"+data.data.url+"'/></div>"

                    $('#img').html(str);
                }else {
                    alert(data.errmsg);
                }

            }
            ,error: function(){
                //请求异常回调
            }
        });
    });


    layui.use('upload', function(){
        var upload = layui.upload;

        //执行实例
        var uploadInst = upload.render({
            elem: '#test3' //绑定元素
            ,url: '/ops/company/upload', //上传接口
            field: 'image'
            ,done: function(res){
                // var data = JSON.parse(res)
                var data = res;
                if(data.errno == 0){
                    var str = "<div id=\"test1\"><img src='"+data.data.url+"' style='width: 120px;'>"
                    str += "<input type='hidden' name='share' value='"+data.data.url+"'/></div>"

                    $('#img3').html(str);
                }else {
                    alert(data.errmsg);
                }

            }
            ,error: function(){
                //请求异常回调
            }
        });
    });


    function delete1(a){
        $(a).parent().remove()
    }

</script>


</body>
</html>

